package com.travel.server.manager.impl.command.data;

import com.travel.common.excel.ExcelData;
import com.travel.common.util.ExcelUtil;
import com.travel.server.manager.dto.request.data.ExportOperateRefundAnalysisRequest;
import com.travel.server.manager.dto.response.EmptyResponse;
import com.travel.server.manager.dto.response.data.QueryOperateRefundAnalysisResponse;
import com.travel.server.manager.impl.command.AbstractCommand;
import com.travel.server.manager.impl.sal.OrderDataSal;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author: LiZhenhui
 * @Date: 2018/12/14 19:13
 * @Desc:
 */
@Component
@Slf4j
public class ExportOperateRefundAnalysisCommand extends AbstractCommand<ExportOperateRefundAnalysisRequest, EmptyResponse> {

    @Autowired
    private QueryOperateRefundAnalysisCommand command;

    @Override
    protected void checkInput(ExportOperateRefundAnalysisRequest request) {

    }

    @Override
    public EmptyResponse handle(ExportOperateRefundAnalysisRequest request) {
        QueryOperateRefundAnalysisResponse response = command.handle(request);
        String head = OrderDataSal.getHead(request.getType());
        String current = "当" + head;
        String last = "前一" + head;
        List<String> title = Arrays.asList(current + "退款订单数", last + "退款订单数", current + "退款金额", last + "退款金额", current + "退款率", last + "退款率");
        List<List<Object>> rows = new ArrayList<>();
        List<Object> objects = new ArrayList<>();
        objects.add(response.getTodayRefundOrder());
        objects.add(response.getYesterdayRefundOrder());
        objects.add(response.getTodayRefundAmount());
        objects.add(response.getYesterdayRefundAmount());
        objects.add(response.getTodayRefundRatio());
        objects.add(response.getYesterdayRefundRatio());
        rows.add(objects);
        String fileName ="退款分析";
        ExcelData excelData = new ExcelData(title, rows, fileName);
        ExcelUtil.exportExcel(getHttpServletResponse(), fileName, excelData);
        return new EmptyResponse();
    }
}
